package com.biz.primus.ms.geo.service;

import com.biz.primus.common.utils.BaiduMapUtil;
import com.biz.primus.common.utils.JsonUtils;
import com.biz.primus.model.geo.vo.BaiduDecodeRespVo;
import com.biz.primus.model.geo.vo.BaiduEncodeRespVo;
import com.biz.primus.model.geo.vo.BaiduLocationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 百度地图api服务
 *
 * @author yanweijin
 * @date 2017/11/18
 */
@Service
@Slf4j
public class BaiduMapApiService {


    /**
     * 正向地理编码
     *
     * @param address 地址
     */
    public BaiduLocationVo encode(String address) {
        String locationEncode = BaiduMapUtil.getLocationEncode(address);
        BaiduEncodeRespVo baiduEncodeRespVo = JsonUtils.json2Obj(locationEncode, BaiduEncodeRespVo.class);
        log.info("调用百度API解析地址{}，\n结果{}", address, baiduEncodeRespVo);
        return baiduEncodeRespVo.getLocation();
    }


    public BaiduDecodeRespVo decode(Double lat, Double lon) {
        String locationDecode = BaiduMapUtil.getLocationDecode(lat, lon);
        BaiduDecodeRespVo baiduDecodeRespVo = JsonUtils.json2Obj(locationDecode, BaiduDecodeRespVo.class);
        log.info("调用百度API解析地址经纬度[{},{}]，\n结果{}", lat, lon, baiduDecodeRespVo);
        return baiduDecodeRespVo;
    }
    //1. 根据经纬度解析地址
    //2. 根据地址解析经纬度


}
